const { app, BrowserWindow } = require('electron');
const { exec } = require('child_process');

function createWindow() {
  const win = new BrowserWindow({
    width: 800,
    height: 600,
    webPreferences: {
      nodeIntegration: true,
      contextIsolation: false,
    },
  });

  win.loadFile('index.html');
}

app.whenReady().then(() => {
  createWindow();

  app.on('activate', () => {
    if (BrowserWindow.getAllWindows().length === 0) {
      createWindow();
    }
  });
});

app.on('window-all-closed', () => {
  if (process.platform !== 'darwin') {
    app.quit();
  }
});

// Function to start Notepad
function startNotepad() {
  exec('notepad.exe', (error, stdout, stderr) => {
    if (error) {
      console.error(`Error starting Notepad: ${error}`);
      return;
    }
    console.log(`Notepad started: ${stdout}`);
  });
}

// Expose the startNotepad function to the renderer process
const { ipcMain } = require('electron');
ipcMain.on('start-notepad', () => {
  startNotepad();
});
